package com.atguigu.gmall.mq.receiver;

import com.atguigu.gmall.mq.config.DeadLetterMqConfig;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;

@Component
@Configuration
public class DeadLetterReceiver {

    /**
     * 已经在 DeadLetterMqConfig 做了配置 故 @RabbitListener 只需监听队列二即可
     * DeadLetterMqConfig.queue_dead_2：监听队列二。因为队列一设置了ttl(10秒钟),过期后变为死信，交换机变为死信交换机
     * 死信交换机和队列二配置绑定关系 故监听队列二。
     * @param msg
     */
    @RabbitListener(queues = DeadLetterMqConfig.queue_dead_2)
    public void get(String msg) {
        System.out.println("接收到的消息：" + msg);

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        System.out.println("接收到消息的时间 ===>>> " + sdf.format(new Date()));
    }
}
